import modelEntity from "./modelEntity";
import RuleResultTemplate from "./RuleResultTemplate";
export default class RuleTemplate extends modelEntity {
  constructor(options) {
    super(options);
    this.TargetType_Guid = options.TargetType_Guid;
    this.Type = options.Type;
    this.Param1 = options.Param1;
    this.Param2 = options.Param2;
    this.Param3 = options.Param3;
    this.Param4 = options.Param4;

    this.ruleResultTemplates = [];
    if (options.ruleResultTemplates) {
      options.ruleResultTemplates.forEach(x => {
        this.ruleResultTemplates.push(new RuleResultTemplate(x));
      })
    }
  }
  static RuleType() {
    return [
      { label: "等于", value: "equal", index: 0, num: 1 },
      { label: "不等于", value: "notEqual", index: 1, num: 1 },
      { label: "大于", value: "big", index: 2, num: 1 },
      { label: "大于等于", value: "bigAndEqual", index: 3, num: 1 },
      { label: "小于", value: "small", index: 4, num: 1 },
      { label: "小于等于", value: "smallAndEqual", index: 5, num: 1 },
      { label: "介于", value: "between", index: 6, num: 2 },
      { label: "包含于", value: "inList", index: 7, num: 1 },
      { label: "不包含于", value: "notInList", index: 8, num: 1 },
    ]
  }
  static newInstance() {
    return new RuleTemplate({
      TargetType_Guid: null,
      Type: null,
      Param1: null,
      Param2: null,
      Param3: null,
      Param4: null,
    })
  }
  static loadList() {
    return new Promise((resolve, reject) => {
      getApp().globalData.api.http_get(`${getApp().globalData.baseUrl}/api/sys/ruletemplate`)
        .then(
          res => {
            console.log(res);
            let list = [];
            res.forEach(x => {
              list.push(new RuleTemplate(x));
            });
            resolve(list);
          }
        )
    })
  }
  create() {
    return new Promise((resolve, reject) => {
      window.api.http_post("/api/sys/ruletemplate", this)
        .then(
          res => {
            let model = new RuleTemplate(res);
            resolve(model);
          }
        )
    })
  }
  delete() {
    return new Promise((resolve, reject) => {
      window.api.http_delete("/api/sys/ruletemplate", this)
        .then(
          res => {
            resolve(res);
          }
        )
    })
  }
  modify() {
    return new Promise((resolve, reject) => {
      window.api.http_put("/api/sys/ruletemplate", this)
        .then(
          res => {
            let model = new RuleTemplate(res);
            resolve(model);
          }
        )
    })
  }
}
